/**
 * 功能说明：文件上传与下载相关 API 封装。
 */
import { get, post } from './http'

export const uploadFile = (file) => {
  const form = new FormData()
  form.append('file', file)
  return post('/files/upload', form, { headers: { 'Content-Type': 'multipart/form-data' } })
}

export const downloadFile = async () => {
  const blob = await get('/files/download', {}, { responseType: 'blob' })
  // 行内注释：在浏览器中触发下载
  const url = window.URL.createObjectURL(blob)
  const a = document.createElement('a')
  a.href = url
  a.download = 'demo.txt'
  a.click()
  window.URL.revokeObjectURL(url)
}